define([
    'jquery',
    'underscore',
    'backbone',
    'text!template/backyard/manage/docer_book_item.html',
    'collection/backyard/manage/docer_book_list'
], function($, _, Backbone, ItemTemplate, DocerCollection){
    
    return Backbone.View.extend({
        el: '[bb-place-book]',
        template: _.template(ItemTemplate),
        
        initialize: function() {
            var _this = this;

            var docerCollection = new DocerCollection();
            docerCollection.fetch({
                success: function (docers) {
                    _this.$el.find('tbody').empty();

                    var docersData = docers.toJSON();
                    for (var i = 0; i < docersData.length; i++) {
                        var _docer = docersData[i];
                        _this.$el.find('tbody').append(_this.template({
                            name: _docer.name,
                            intro: _docer.intro,
                            version: _docer.version,
                            modified: _docer.modified
                        }));
                    }
                }
            });
        }
    });
});
